using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace Extra.Data
{
    public class xfmAttachDatabase : XtraForm
    {
        private string _mConnectString = "";
        private SimpleButton btnCancel;
        private SimpleButton btnLogin;
        private IContainer components = null;
        private LabelControl labelControl4;
        private LabelControl labelControl5;
        public TextEdit txtDatabase;
        private ButtonEdit txtPath;

        public event AttachDatabaseEventHander AttachDatabase;

        public xfmAttachDatabase(string connectionString)
        {
            this.InitializeComponent();
            this._mConnectString = connectionString;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!File.Exists(this.txtPath.Text))
            {
                XtraMessageBox.Show("Tập tin kh\x00f4ng tồn tại!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.txtDatabase.Text == "")
            {
                XtraMessageBox.Show("Nhập t\x00ean dữ liệu cần đăng k\x00fd!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                base.Enabled = false;
                this.RaiseAttachDatabaseEventHander(this.txtDatabase.Text, this.txtPath.Text);
            }
        }

        private void btnOrther_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter = "Microsoft SQL Server File(*.mdf)|*.mdf|All File(*.*)|*.*",
                FilterIndex = 0
            };
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtPath.Text = dialog.FileName;
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xfmAttachDatabase));
            SerializableAppearanceObject appearance = new SerializableAppearanceObject();
            this.btnCancel = new SimpleButton();
            this.btnLogin = new SimpleButton();
            this.txtDatabase = new TextEdit();
            this.labelControl5 = new LabelControl();
            this.labelControl4 = new LabelControl();
            this.txtPath = new ButtonEdit();
            this.txtDatabase.Properties.BeginInit();
            this.txtPath.Properties.BeginInit();
            base.SuspendLayout();
            this.btnCancel.Image = (Image)manager.GetObject("btnCancel.Image");
            this.btnCancel.Location = new Point(0x14d, 0x54);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(80, 0x17);
            this.btnCancel.TabIndex = 0x2c;
            this.btnCancel.Text = "Đ\x00f3ng";
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.btnLogin.Image = (Image)manager.GetObject("btnLogin.Image");
            this.btnLogin.Location = new Point(0xf5, 0x54);
            this.btnLogin.Name = "btnLogin";
            this.btnLogin.Size = new Size(80, 0x17);
            this.btnLogin.TabIndex = 0x2b;
            this.btnLogin.Text = "Thực Hiện";
            this.btnLogin.Click += new EventHandler(this.btnLogin_Click);
            this.txtDatabase.EditValue = "";
            this.txtDatabase.Location = new Point(0x54, 0x2a);
            this.txtDatabase.Name = "txtDatabase";
            this.txtDatabase.Size = new Size(0x149, 20);
            this.txtDatabase.TabIndex = 0x26;
            this.labelControl5.Location = new Point(13, 0x10);
            this.labelControl5.Name = "labelControl5";
            this.labelControl5.Size = new Size(0x37, 13);
            this.labelControl5.TabIndex = 0x29;
            this.labelControl5.Text = "Đường Dẫn";
            this.labelControl4.Location = new Point(13, 0x2c);
            this.labelControl4.Name = "labelControl4";
            this.labelControl4.Size = new Size(0x24, 13);
            this.labelControl4.TabIndex = 40;
            this.labelControl4.Text = "Dữ Liệu";
            this.txtPath.Location = new Point(0x54, 14);
            this.txtPath.Name = "txtPath";
            this.txtPath.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Glyph, "", -1, true, true, false, ImageLocation.MiddleCenter, (Image)manager.GetObject("txtPath.Properties.Buttons"), new KeyShortcut(Keys.None), appearance, "", null, null, true) });
            this.txtPath.Properties.ReadOnly = true;
            this.txtPath.Properties.ButtonClick += new ButtonPressedEventHandler(this.txtPath_Properties_ButtonClick);
            this.txtPath.Size = new Size(0x149, 0x16);
            this.txtPath.TabIndex = 0x27;
            this.txtPath.TabStop = false;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x1ad, 0x73);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnLogin);
            base.Controls.Add(this.txtDatabase);
            base.Controls.Add(this.labelControl5);
            base.Controls.Add(this.labelControl4);
            base.Controls.Add(this.txtPath);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmAttachDatabase";
            base.ShowIcon = false;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "Đăng K\x00fd Cở Sở Dữ Liệu";
            this.txtDatabase.Properties.EndInit();
            this.txtPath.Properties.EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                base.Close();
                return true;
            }
            return false;
        }

        private void RaiseAttachDatabaseEventHander(string db, string mdffile)
        {
            if (this.AttachDatabase != null)
            {
                this.AttachDatabase(this, db, mdffile);
            }
        }

        private void txtPath_Properties_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter = "Microsoft SQL Server File(*.mdf)|*.mdf|All File(*.*)|*.*",
                FilterIndex = 0
            };
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtPath.Text = dialog.FileName;
            }
        }

        public delegate void AttachDatabaseEventHander(object sender, string db, string mdffile);
    }

}
